﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Api.Filter;
using Customer.Bussiness_Service;
using Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ServiceCore;

namespace Customer.Areas.crm_warehouse.Controllers
{
    [ApiController, Area("warehouse"), Route("/warehouse/materiel/[action]"), Customer_Admin]
    public class materielController : ControllerBase
    {
        private readonly Imateriel_service _service;
        private readonly IToole_DI _tool;
        public materielController(Imateriel_service service, IToole_DI tool)
        {
            _service = service;
            _tool = tool;
        }
        /// <summary>
        /// 获取物料类型
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel get_type_tree(bool only_can_use = false)
        {
            var result = _service.get_materiel_type_tree(only_can_use);
            return result;
        }

        /// <summary>
        /// 获取物料类型列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel get_materiel_type_list(string parent_id = "0")
        {
            var result = _service.get_materiel_type_list(parent_id);
            return result;
        }
        /// <summary>
        /// 添加/编辑物料类型
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel save_type(string materiel_type_id, string type_name, string parent_id = "0")
        {
            var result = _service.save_materiel_type(materiel_type_id, type_name, parent_id);
            return result;
        }
        /// <summary>
        /// 设置物料类型状态
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel set_type_state(string materiel_type_id, materiel_type_state? materiel_type_state)
        {
            var result = _service.set_materiel_type_state(materiel_type_id, materiel_type_state);
            return result;
        }

        /// <summary>
        /// 保存物料信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultObjModel save(materiel_base Params)
        {
            var result = _service.save_materiel(Params);
            return result;
        }
        /// <summary>
        /// 获取物料列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultListModel<search_materiel_base> get_pagelist(materiel_base_query query)
        {
            var result = _service.get_materiel_pagelist(query);
            return result;
        }

        /// <summary>
        /// 设置物料状态
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel set_state(string materiel_id, materiel_base_state? materiel_base_state)
        {
            var result = _service.set_materiel_state(materiel_id, materiel_base_state);
            return result;
        }
        /// <summary>
        /// 根据完整物料编号获取物料详情
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel get_materiel_model(string materiel_total_show_no)
        {
            var result = _service.get_materiel_model(materiel_total_show_no);
            return result;
        }  
    }
}